const Sequelize = require('sequelize');
module.exports = function(sequelize, DataTypes) {
  return sequelize.define('foresee', {
    id: {
      autoIncrement: true,
      type: DataTypes.INTEGER.UNSIGNED,
      allowNull: false,
      primaryKey: true
    },
    time: {
      type: DataTypes.DATE,
      allowNull: false,
      comment: "预约时间"
    },
    memo: {
      type: DataTypes.TEXT,
      allowNull: true,
      comment: "备注"
    },
    state: {
      type: DataTypes.ENUM('等待处理','预约成功','预约失败'),
      allowNull: true,
      defaultValue: "等待处理",
      comment: "状态"
    },
    patient_id: {
      type: DataTypes.INTEGER.UNSIGNED,
      allowNull: false,
      references: {
        model: 'patient',
        key: 'id'
      }
    },
    doctor_id: {
      type: DataTypes.INTEGER.UNSIGNED,
      allowNull: false,
      references: {
        model: 'user',
        key: 'id'
      }
    }
  }, {
    sequelize,
    tableName: 'foresee',
    timestamps: true,
    indexes: [
      {
        name: "PRIMARY",
        unique: true,
        using: "BTREE",
        fields: [
          { name: "id" },
        ]
      },
      {
        name: "foresee_ibfk_1",
        using: "BTREE",
        fields: [
          { name: "patient_id" },
        ]
      },
      {
        name: "foresee_ibfk_2",
        using: "BTREE",
        fields: [
          { name: "doctor_id" },
        ]
      },
    ]
  });
};
